"""
该脚本是同步微信signature的，每1个半小时同步，使用linux 的crontab.不能使用相对路径
"""
import json
import requests


def update_signatrue(save_path,token):#save_path,
    """
    微信的signature是2个小时
    :param save_path:
    :param token:
    :return:
    """
    user_name='老张'
    userid='cgai2020'
    url='https://openai.weixin.qq.com/openapi/sign/{}'.format(token)
    data={'user_name':user_name,'userid':userid}
    head = {"Content-Type": "application/json"}
    respons = requests.post(url, json.dumps(data), headers=head)
    signature=''
    if respons:
        signature=respons.json()['signature']
        with open(save_path,'w',encoding='utf8') as w:
            w.write(signature)
    return signature


if __name__ == '__main__':
    APPID = 'gAN9RwevbV1fbx4'
    TOKEN = 'uEj3814l9YPZFQiNRpu0kymIANqxsu'
    EncodingAESKey = 'ue2gZyLMsOK53D5U5VKUL67v4x7zHMekMGbqWSoOBG'
    cgai_url = 'https://openai.weixin.qq.com/openapi/aibot/{}'.format(TOKEN)
    save_path = '/home/mz/HAServer/conf/signature'
    update_signatrue(save_path,TOKEN)